﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Noris.Tools.FrxEditor.Forms
{
    /// <summary>
    /// Testovací formulář
    /// </summary>
	public partial class TestGrids : Form
	{
        /// <summary>
        /// Testovací formulář, konstruktor
        /// </summary>
		public TestGrids()
		{
			InitializeComponent();
            InitGridMem();
            //InitGridDb();
		}
        private void InitGridMem()
        {
            Data.SimpleDataTable table = Data.SimpleDataTable.Empty;
            Data.SimpleDataColumn column;
            column = table.Columns.Add("param_name", "Název", typeof(string));
            column = table.Columns.Add("param_type", "Typ", typeof(string), "numeric,char,int,bigint,datetime");
            column = table.Columns.Add("param_value", "Hodnota", typeof(string));

            table.Rows.Add(":ra_cs", "numeric", "");
            table.Rows.Add(":datum_od", "datetime", "");

            this.DataGrid.DataTable = table;
            this.DataGrid.SimpleEditMode = Data.SimpleDataGridEditMode.EditContent;
            // this.DataGrid.SimpleEditMode = Data.SimpleDataGridEditMode.EditContentAndRows;

            this.DataGrid.Columns[0].ReadOnly = true;
            this.DataGrid.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }
        private void InitGridDb()
        {
            string sql = "select top 450 * from lcs.kmenova_karta_skladu";
            System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
            long freq = System.Diagnostics.Stopwatch.Frequency;
            Data.SimpleDataTable table = Data.SimpleDataTable.Load(sql, this._InitColumn);
            long tick1 = sw.ElapsedTicks;

            this.DataGrid.DataTable = table;
            long tick2 = sw.ElapsedTicks;
            
            float time1 = 1000f * (float)tick1 / (float)freq;
            float time2 = 1000f * (float)(tick2 - tick1) / (float)freq;
            System.Windows.Forms.MessageBox.Show(" DataLoad=" + time1.ToString("## ##0.000") + " milisec,\r\n GridLoad=" + time2.ToString("## ##0.000") + " milisec.");

            this.DataGrid.SimpleEditMode = Data.SimpleDataGridEditMode.EditContent;

            this.DataGrid.Columns[0].ReadOnly = true;
            this.DataGrid.Columns[1].ReadOnly = true;
            //((Noris.Tools.FrxEditor.Data.SimpleDataGridCell)this.DataGrid.Rows[5].Cells[3]).Enabled = false;
        }
        private void _InitColumn(Data.SimpleDataColumn column)
        {
            Noris.Schedule.Support.Green.ClassInfo classInfo = Noris.Schedule.Support.Green.Repository.Classes[343];
            column.Attribute = classInfo.FindAttribute(column.ColumnName.ToLower(), false);
            column.Relation = classInfo.FindStaticRelation(column.ColumnName.ToLower(), false);

            if (column.ColumnIndex == 6)
                column.EditStyleValues = "První;Druhý,malý;Třetí velký";
        }
	}
}
